package br.com.pheat.servlets;

import java.util.List;
import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.pheat.beans.RefeicaoAlimento;
import br.com.pheat.dao.AlimentoDAO;

public class AlimentoConsultaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public AlimentoConsultaServlet() {
        super();
    }

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			response.setContentType("text/html");
			Integer codigo_refeicao = Integer.parseInt(request.getParameter("codigo_refeicao"));
			List<RefeicaoAlimento> refeicao = AlimentoDAO.getRefeicaoAlimento(codigo_refeicao);

			request.setAttribute("refeicaoAlimento", refeicao);
			RequestDispatcher dispatcher = request.getRequestDispatcher("consultaAlimento.jsp");
			dispatcher.forward(request, response);
		}catch(Exception e){
			response.sendRedirect("erro.jsp");
		}
	}
}
